﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;

namespace SLWebApp
{
    public partial class ShipSchedule : UserControl
    {
        ServiceReference_HB.ServiceForSLClient clientService = new ServiceReference_HB.ServiceForSLClient();
        string userid = string.Empty;

        ChildWindows.ChildWindow_ShipSchedule shipSchedule = null; //新增、修改船期界面。
        ChildWindows.ChildWindow_VesselBerthes window_Berthes = null;//新增、修改靠泊界面 。
        ChildWindows.ChildWindow_Voyage window_Voyage = null;//新增、修改航次界面。
        ServiceReference_HB.UM_VesselSchedules mVesselSchedules = null;//船期表里点选一行数据的对像。 
        /// <summary>
        /// 所有船名称。
        /// </summary>
        System.Collections.ObjectModel.ObservableCollection<ServiceReference_HB.ST_Vessels> listVess = null;
        /// <summary>
        /// 查寻出来的船期数据。
        /// </summary>
        System.Collections.ObjectModel.ObservableCollection<ServiceReference_HB.UM_VesselSchedules> list_VesselSchedule = null;
        public ShipSchedule()
        {
            InitializeComponent();
            System.Windows.Browser.HtmlDocument doc = System.Windows.Browser.HtmlPage.Document;
            if (doc.QueryString.Count > 0)
            {
                userid = doc.QueryString["userid"].ToString();
            }
            Init();
        }

        #region 船期数据初始化.
        /// <summary>
        /// 船期数据初始化.
        /// </summary>
        private void Init()
        {
            try
            {
                progressbar_ShipSchedule.IsBusy = true;
                ////初始化船期数据,初始时不显示船期数据，让用户查询显示出来。
                //clientService.GetVesselSchedulesAsync(string.Empty,string.Empty);
                //clientService.GetVesselSchedulesCompleted += new EventHandler<ServiceReference_HB.GetVesselSchedulesCompletedEventArgs>(clientService_GetVesselSchedulesCompleted);
                //初始化船名数据。
                clientService.GetAllVesselsAsync(string.Empty, string.Empty);
                clientService.GetAllVesselsCompleted -= new EventHandler<ServiceReference_HB.GetAllVesselsCompletedEventArgs>(clientService_GetAllVesselsCompleted);
                clientService.GetAllVesselsCompleted += new EventHandler<ServiceReference_HB.GetAllVesselsCompletedEventArgs>(clientService_GetAllVesselsCompleted);
                //码头数据
                clientService.GetAllTerminallsAsync();
                clientService.GetAllTerminallsCompleted -= new EventHandler<ServiceReference_HB.GetAllTerminallsCompletedEventArgs>(clientService_GetAllTerminallsCompleted);
                clientService.GetAllTerminallsCompleted += new EventHandler<ServiceReference_HB.GetAllTerminallsCompletedEventArgs>(clientService_GetAllTerminallsCompleted);
            }
            catch
            { progressbar_ShipSchedule.IsBusy = false; }
        }


        //初始化船名数据。
        void clientService_GetAllVesselsCompleted(object sender, ServiceReference_HB.GetAllVesselsCompletedEventArgs e)
        {
            progressbar_ShipSchedule.IsBusy = false; 
            listVess = e.Result;
            autoComENName.ItemsSource = from vess in listVess
                                        select vess.VSL_ENNAME + '(' + vess.VSL_CD + ')';
        }
        //初始化船期数据
        void clientService_GetVesselSchedulesCompleted(object sender, ServiceReference_HB.GetVesselSchedulesCompletedEventArgs e)
        {
            list_VesselSchedule = e.Result;
            dataGridVesselSchedule.ItemsSource = list_VesselSchedule;

            progressbar_ShipSchedule.IsBusy = false;
        }
        //码头数据
        void clientService_GetAllTerminallsCompleted(object sender, ServiceReference_HB.GetAllTerminallsCompletedEventArgs e)
        {
            System.Collections.ObjectModel.ObservableCollection<ServiceReference_HB.UM_Terminals> list_ter = e.Result;
            this.txtTerminal.ItemsSource = list_ter;
        }
        #endregion

        #region 点击船期数据显示对应的靠泊数据、航次数据、箱量数据。
        private void dataGridVesselSchedule_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (var item in e.AddedItems)
            {
                mVesselSchedules = item as ServiceReference_HB.UM_VesselSchedules;
                if (mVesselSchedules != null)
                {
                    //靠泊数据
                    clientService.GetVesselBerthesAsync(mVesselSchedules.SCD_ID);
                    clientService.GetVesselBerthesCompleted -= new EventHandler<ServiceReference_HB.GetVesselBerthesCompletedEventArgs>(clientService_GetVesselBerthesCompleted);
                    clientService.GetVesselBerthesCompleted += new EventHandler<ServiceReference_HB.GetVesselBerthesCompletedEventArgs>(clientService_GetVesselBerthesCompleted);
                    //航次数据
                    clientService.GetVoyagesAsync(mVesselSchedules.SCD_ID);
                    clientService.GetVoyagesCompleted -= new EventHandler<ServiceReference_HB.GetVoyagesCompletedEventArgs>(clientService_GetVoyagesCompleted);
                    clientService.GetVoyagesCompleted += new EventHandler<ServiceReference_HB.GetVoyagesCompletedEventArgs>(clientService_GetVoyagesCompleted);
                    //箱量数据 
                    //clientService.GetVoyageAmountsAsync(mVesselSchedules.SCD_ID);
                    //clientService.GetVoyageAmountsCompleted += new EventHandler<ServiceReference_HB.GetVoyageAmountsCompletedEventArgs>(clientService_GetVoyageAmountsCompleted);
                }
            }

        }

        //靠泊数据完成事件。
        System.Collections.ObjectModel.ObservableCollection<ServiceReference_HB.UM_Vessel_Berthes> list_Vessel_Berthes = null;
        void clientService_GetVesselBerthesCompleted(object sender, ServiceReference_HB.GetVesselBerthesCompletedEventArgs e)
        {
            list_Vessel_Berthes = e.Result;
            this.dataGridVesselBerthes.ItemsSource = list_Vessel_Berthes;
        }

        System.Collections.ObjectModel.ObservableCollection<ServiceReference_HB.UM_Voyages> list_Voyages = null;
        //航次数据完成事件。
        void clientService_GetVoyagesCompleted(object sender, ServiceReference_HB.GetVoyagesCompletedEventArgs e)
        {
            list_Voyages = e.Result;
            this.dataGridVoyage.ItemsSource = list_Voyages;
            if (isSendEvent_Voyage)
            {
                switch (list_Voyages.Count)
                {
                    case 0:
                        {
                            mVesselSchedules.SCD_IVOYAGE = string.Empty;

                            mVesselSchedules.SCD_EVOYAGE = string.Empty;
                        }; break;
                    case 1:
                        {
                            if (list_Voyages[0].VOY_IEFG == "I")//进口
                            {
                                mVesselSchedules.SCD_IVOYAGE = list_Voyages[0].VOY_VOYAGE;
                                mVesselSchedules.SERVICELINE = "I:" + list_Voyages[0].SLN_NAME;
                            }
                            else//出口
                            {
                                mVesselSchedules.SCD_EVOYAGE = list_Voyages[0].VOY_VOYAGE;
                                mVesselSchedules.SERVICELINE = "E:" + list_Voyages[0].SLN_NAME;
                            }
                        }; break;
                    case 2:
                        {
                            string serviceLine = string.Empty;
                            foreach (ServiceReference_HB.UM_Voyages item in list_Voyages)
                            {
                                if (item.VOY_IEFG == "I")//进口
                                {
                                    mVesselSchedules.SCD_IVOYAGE = item.VOY_VOYAGE;
                                    if (serviceLine.Length == 0)
                                        serviceLine = "I:" + item.SLN_NAME;
                                    else
                                        serviceLine.Insert(0, "I:" + item.SLN_NAME);
                                }
                                else//出口
                                {
                                    mVesselSchedules.SCD_EVOYAGE = item.VOY_VOYAGE;
                                    serviceLine += "E:" + item.SLN_NAME;
                                }
                            }
                            mVesselSchedules.SERVICELINE = serviceLine;
                        }; break;
                }
                isSendEvent_Voyage = false;
            }

        }
        //箱量数据 
        //void clientService_GetVoyageAmountsCompleted(object sender, ServiceReference_HB.GetVoyageAmountsCompletedEventArgs e)
        //{
        //    System.Collections.ObjectModel.ObservableCollection<ServiceReference_HB.UM_Voyage_Amounts> list_VoyageAmount = e.Result;
        //    this.dataGridVoyageAmounts.ItemsSource = list_VoyageAmount;
        //}
        #endregion

        #region 界面上的事件
        //显示船中文名称。选择好英文名后。
        private void autoComENName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var result = from vess in listVess
                             where vess.VSL_ENNAME + '(' + vess.VSL_CD + ')' == e.AddedItems[0].ToString()
                             select vess;
                List<ServiceReference_HB.ST_Vessels> tem = result.ToList();
                if (tem.Count > 0)
                {
                    txtVesselCNName.Text = tem[0].VSL_CNNAME;
                    txtVesselCNName.Tag = tem[0].VSL_ENNAME;
                }
            }
        }

        //船期工具栏里的查询
        private void btnSearch_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            progressbar_ShipSchedule.IsBusy = true;
            string str = "";
            if (!string.IsNullOrEmpty(autoComENName.Text))//英文船名
            {
                str += " b.vsl_enname ='" + txtVesselCNName.Tag.ToString() + "'";
            }
            if (!string.IsNullOrEmpty(txtInVoyage.Text))//进口航次
            {
                if (string.IsNullOrEmpty(str))
                {
                    str += "  a.scd_ivoyage ='" + txtInVoyage.Text + "' ";
                }
                else
                {
                    str += " and a.scd_ivoyage ='" + txtInVoyage.Text + "' ";
                }
            }
            if (!string.IsNullOrEmpty(txtExVoyage.Text))//出口航次
            {
                if (string.IsNullOrEmpty(str))
                {
                    str += " a.scd_evoyage ='" + txtExVoyage.Text + "'";
                }
                else
                {
                    str += " and a.scd_evoyage ='" + txtExVoyage.Text + "'";
                }
            }
            if (!string.IsNullOrEmpty(dateETA_start.Text))//抵港时间
            {
                if (!string.IsNullOrEmpty(dateETA_end.Text))
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        str += " a.scd_eta >= to_date('" + dateETA_start.Text + "','yyyy/mm/dd') and a.scd_eta <= to_date('" + dateETA_end.Text + "','yyyy/mm/dd')";
                    }
                    else
                    {
                        str += " and a.scd_eta >= to_date('" + dateETA_start.Text + "','yyyy/mm/dd') and a.scd_eta <= to_date('" + dateETA_end.Text + "','yyyy/mm/dd')";
                    }
                }
                else
                {
                    MessageBox.Show("请填写抵港结束时间！", "提示", MessageBoxButton.OK);
                }
            }
            if (!string.IsNullOrEmpty(dateETD_start.Text))//离港时间
            {
                if (!string.IsNullOrEmpty(dateETD_end.Text))
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        str += " a.scd_etd >= to_date('" + dateETD_start.Text + "','yyyy/mm/dd') and a.scd_etd <= to_date('" + dateETD_end.Text + "','yyyy/mm/dd')";
                    }
                    else
                    {
                        str += " and a.scd_etd >= to_date('" + dateETD_start.Text + "','yyyy/mm/dd') and a.scd_etd <= to_date('" + dateETD_end.Text + "','yyyy/mm/dd')";
                    }
                }
                else
                {
                    MessageBox.Show("请填写离港结束时间！", "提示", MessageBoxButton.OK);
                }
            }
            if (txtTerminal.SelectedItem != null)
            {
                ServiceReference_HB.UM_Terminals mTerinal = txtTerminal.SelectedItem as ServiceReference_HB.UM_Terminals;
                if (string.IsNullOrEmpty(str))
                {
                    str += " c.cst_cstm ='" + mTerinal.CST_CSTM + "'";
                }
                else
                {
                    str += " and c.cst_cstm ='" + mTerinal.CST_CSTM + "'";
                }
            }
            clientService.GetVesselSchedulesAsync(str, string.Empty);
            clientService.GetVesselSchedulesCompleted -= new EventHandler<ServiceReference_HB.GetVesselSchedulesCompletedEventArgs>(clientService_GetVesselSchedulesCompleted);
            clientService.GetVesselSchedulesCompleted += new EventHandler<ServiceReference_HB.GetVesselSchedulesCompletedEventArgs>(clientService_GetVesselSchedulesCompleted);
            System.Threading.Thread.Sleep(1000);
        }

        //船期工具栏里的新增
        private void btnAdd_VesselSchedule_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (shipSchedule == null) //弹出新增窗口。
            {
                shipSchedule = new ChildWindows.ChildWindow_ShipSchedule(listVess, userid);
                shipSchedule.OnAddShipSchedule += new MouseButtonEventHandler(shipSchedule_OnAddShipSchedule);
            }
            shipSchedule.SetDropdownListEnable();
            shipSchedule.IsAdd_Modefy = true;
            shipSchedule.ClearText();//清除内容.
            shipSchedule.SetDefault();//设置初始值。
            shipSchedule.Show();
        }
        //新增数据或者修改数据时通知本窗口修改
        void shipSchedule_OnAddShipSchedule(object sender, MouseButtonEventArgs e)
        {
            clientService.GetVesselSchedulesAsync(string.Empty, string.Empty);//重新绑定。
            //clientService.GetVesselSchedulesCompleted -= new EventHandler<ServiceReference_HB.GetVesselSchedulesCompletedEventArgs>(clientService_GetVesselSchedulesCompleted);
            //clientService.GetVesselSchedulesCompleted += new EventHandler<ServiceReference_HB.GetVesselSchedulesCompletedEventArgs>(clientService_GetVesselSchedulesCompleted);
        }

        //修改船期数据.
        private void btnModefy_Schedule_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ServiceReference_HB.UM_VesselSchedules mSchedule = dataGridVesselSchedule.SelectedItem as ServiceReference_HB.UM_VesselSchedules;
            if (mSchedule == null)
            {
                MessageBox.Show("请选择一行数据！", "提示", MessageBoxButton.OK);
                return;
            }
            if (shipSchedule == null)
            {
                shipSchedule = new ChildWindows.ChildWindow_ShipSchedule(listVess, userid);
                shipSchedule.OnAddShipSchedule += new MouseButtonEventHandler(shipSchedule_OnAddShipSchedule);
            }
            shipSchedule.mUM_VesselSchedules = mSchedule;
            shipSchedule.IsAdd_Modefy = false;
            shipSchedule.Show();
            shipSchedule.Inited();
        }

        //班期删除事件！。
        ServiceReference_HB.UM_VesselSchedules mSchedule_del = null;
        private void btnDel_VesselSchedule_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ServiceReference_HB.UM_VesselSchedules mSchedule_del = dataGridVesselSchedule.SelectedItem as ServiceReference_HB.UM_VesselSchedules;
            if (mSchedule_del == null)
            {
                MessageBox.Show("请选择一行数据！", "提示", MessageBoxButton.OK);
                return;
            }
            else if (!string.IsNullOrEmpty(mSchedule_del.SCD_IVOYAGE) || !string.IsNullOrEmpty(mSchedule_del.SCD_EVOYAGE) || !string.IsNullOrEmpty(mSchedule_del.CST_CSTM))
            {
                MessageBox.Show("请您手动先删除该船期的进/出口航次，以及靠泊数据。", "提示", MessageBoxButton.OK);
                return;
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("您确定删除该数据吗？", "提示", MessageBoxButton.OKCancel);
                if (result.ToString() == "OK")
                {
                    clientService.DeleteBySCD_IDAsync(mSchedule_del.SCD_ID.ToString());
                    clientService.DeleteBySCD_IDCompleted -= new EventHandler<ServiceReference_HB.DeleteBySCD_IDCompletedEventArgs>(clientService_DeleteBySCD_IDCompleted);
                    clientService.DeleteBySCD_IDCompleted += new EventHandler<ServiceReference_HB.DeleteBySCD_IDCompletedEventArgs>(clientService_DeleteBySCD_IDCompleted);

                    //记录日志.
                }
            }
        }

        //班期删除操作完成事件！。
        void clientService_DeleteBySCD_IDCompleted(object sender, ServiceReference_HB.DeleteBySCD_IDCompletedEventArgs e)
        {
            string str = e.Result;
            if (str.Substring(0, 1) == "1")
            {
                MessageBox.Show(str.Substring(2, str.Length - 2));
                //要根据返回数据
                if (mSchedule_del != null)
                    list_VesselSchedule.Remove(mSchedule_del);
            }
            else
            {
                MessageBox.Show(e.Result);
            }
        }


        /// <summary>
        /// 靠泊新增。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVesselBerthe_Add_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (window_Berthes == null)
            {
                window_Berthes = new ChildWindows.ChildWindow_VesselBerthes();
            }
            window_Berthes = new ChildWindows.ChildWindow_VesselBerthes();
            window_Berthes.Is_Add_Modefy = true;
            window_Berthes.mSCD_ID = mVesselSchedules.SCD_ID.ToString();
            window_Berthes.mUser_ID = userid;
            window_Berthes.OnAdded_ModefyData -= new MouseButtonEventHandler(window_Berthes_OnAdded_ModefyData);
            window_Berthes.OnAdded_ModefyData += new MouseButtonEventHandler(window_Berthes_OnAdded_ModefyData);

            window_Berthes.Show();
        }

        ServiceReference_HB.UM_Vessel_Berthes mberthes = null;// 记录当前靠泊。
        /// <summary>
        ///  删除靠泊数据.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVessBerthe_Del_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (dataGridVesselBerthes.SelectedItem != null)
            {
                mberthes = dataGridVesselBerthes.SelectedItem as ServiceReference_HB.UM_Vessel_Berthes;
                MessageBoxResult result = MessageBox.Show("您确定删除该数据吗？", "提示", MessageBoxButton.OKCancel);
                if (result.ToString() == "Cancel")
                    return;
                //通过数据库删除。
                clientService.InsertUpdateVesselBerthAsync(3, mberthes.VBT_SCD_ID.ToString(), DateTime.MinValue,
                    DateTime.MinValue, null, null, null, null,
                    null, null, null, null, mberthes.VBT_ID.ToString(), null);
                clientService.InsertUpdateVesselBerthCompleted -= new EventHandler<ServiceReference_HB.InsertUpdateVesselBerthCompletedEventArgs>(clientService_InsertUpdateVesselBerthCompleted);
                clientService.InsertUpdateVesselBerthCompleted += new EventHandler<ServiceReference_HB.InsertUpdateVesselBerthCompletedEventArgs>(clientService_InsertUpdateVesselBerthCompleted);
            }
            else
            {
                MessageBox.Show("请选择一行数据！", "提示", MessageBoxButton.OK);
                return;
            }
        }

        void clientService_InsertUpdateVesselBerthCompleted(object sender, ServiceReference_HB.InsertUpdateVesselBerthCompletedEventArgs e)
        {
            string str = e.Result.Trim();
            if (str.Substring(0, 1) == "1")
            {
                MessageBox.Show(str.Substring(2, str.Length - 2));
                list_Vessel_Berthes.Remove(mberthes);
            }
            else
            {
                MessageBox.Show(e.Result);
            }
        }
        /// <summary>
        ///  修改靠泊数据.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVessBerthe_Modefy_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (dataGridVesselBerthes.SelectedItem == null)
            {
                MessageBox.Show("请选择一条靠泊数据！", "提示", MessageBoxButton.OK);
                return;
            }

            ServiceReference_HB.UM_Vessel_Berthes berthes = dataGridVesselBerthes.SelectedItem as ServiceReference_HB.UM_Vessel_Berthes;
            if (window_Berthes == null)
            {
                window_Berthes = new ChildWindows.ChildWindow_VesselBerthes();
                window_Berthes.OnAdded_ModefyData -= new MouseButtonEventHandler(window_Berthes_OnAdded_ModefyData);
                window_Berthes.OnAdded_ModefyData += new MouseButtonEventHandler(window_Berthes_OnAdded_ModefyData);
            }
            window_Berthes.Is_Add_Modefy = false;
            window_Berthes.mSCD_ID = mVesselSchedules.SCD_ID.ToString();
            window_Berthes.mUser_ID = userid;
            window_Berthes.mVessel_Berthes = berthes;
            window_Berthes.mVBT_ID = berthes.VBT_ID.ToString();

            window_Berthes.Inited();
            window_Berthes.Show();

        }
        //更新数据完成事件
        void window_Berthes_OnAdded_ModefyData(object sender, MouseButtonEventArgs e)
        {
            if (mVesselSchedules != null)
                clientService.GetVesselBerthesAsync(mVesselSchedules.SCD_ID);
        }

        /// <summary>
        /// 新增航次表数据。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVoyage_ADD_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (window_Voyage == null)
            {
                window_Voyage = new ChildWindows.ChildWindow_Voyage();
            }
            window_Voyage.Is_Add_Modefy = true;
            window_Voyage.mSCD_ID = mVesselSchedules.SCD_ID.ToString();
            window_Voyage.mUser_ID = userid;
            window_Voyage.OnAdd_ModefyEvent -= new MouseButtonEventHandler(window_Voyage_OnAdd_ModefyEvent);
            window_Voyage.OnAdd_ModefyEvent += new MouseButtonEventHandler(window_Voyage_OnAdd_ModefyEvent);
            window_Voyage.Show();
        }


        ServiceReference_HB.UM_Voyages mVoyages = null;//记录前选择的航次数据。
        /// <summary>
        /// 删除航次
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVoyage_Dele_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (dataGridVoyage.SelectedItem != null)
            {
                mVoyages = dataGridVoyage.SelectedItem as ServiceReference_HB.UM_Voyages;
                MessageBoxResult result = MessageBox.Show("您确定删除该数据吗？", "提示", MessageBoxButton.OKCancel);
                if (result.ToString() == "Cancel")
                    return;
                //删除航次.
                clientService.InsertUpdateProcessVoyageAsync(3, Convert.ToInt32(mVoyages.VOY_ID), int.Parse(userid), mVoyages.VOY_IEFG, 0, Convert.ToInt32(mVoyages.VOY_SCD_ID), 0, string.Empty, string.Empty);
                clientService.InsertUpdateProcessVoyageCompleted -= new EventHandler<ServiceReference_HB.InsertUpdateProcessVoyageCompletedEventArgs>(clientService_InsertUpdateProcessVoyageCompleted);
                clientService.InsertUpdateProcessVoyageCompleted += new EventHandler<ServiceReference_HB.InsertUpdateProcessVoyageCompletedEventArgs>(clientService_InsertUpdateProcessVoyageCompleted);
                // list_Voyages.Remove(Voyages);
                //通过数据库删除。
            }
            else
            {
                MessageBox.Show("请选择一行数据！", "提示", MessageBoxButton.OK);
                return;
            }
        }
        //删除航次,完成事件。
        void clientService_InsertUpdateProcessVoyageCompleted(object sender, ServiceReference_HB.InsertUpdateProcessVoyageCompletedEventArgs e)
        {
            string str = e.Result.Trim();
            if (str.Substring(0, 1) == "1")
            {
                MessageBox.Show(str.Substring(2, str.Length - 2));
                //根据航次修改航班信息
                if (mVoyages != null)
                {
                    string ie_str = mVesselSchedules.SERVICELINE;
                    if (mVoyages.VOY_IEFG == "I")//进口
                    {
                        mVesselSchedules.SCD_IVOYAGE = string.Empty;
                        mVesselSchedules.SERVICELINE = ie_str.Replace("I:" + mVoyages.SLN_NAME, "I:");
                    }
                    else//出口
                    {
                        mVesselSchedules.SCD_EVOYAGE = string.Empty;
                        mVesselSchedules.SERVICELINE = ie_str.Replace("E:" + mVoyages.SLN_NAME, "E:");
                    }
                }

                list_Voyages.Remove(mVoyages);
                //mVesselSchedules.SCD_IVOYAGE
            }
            else
            {
                MessageBox.Show(e.Result);
            }
        }

        /// <summary>
        /// 修改航次.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVoyage_Modefy_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ServiceReference_HB.UM_Voyages theVoyage = dataGridVoyage.SelectedItem as ServiceReference_HB.UM_Voyages;
            if (theVoyage == null)
            {
                MessageBox.Show("请选择一行航次信息。", "提示", MessageBoxButton.OK);
                return;
            }
            if (window_Voyage == null)
            {
                window_Voyage = new ChildWindows.ChildWindow_Voyage();
                window_Voyage.OnAdd_ModefyEvent += new MouseButtonEventHandler(window_Voyage_OnAdd_ModefyEvent);
            }
            window_Voyage.Is_Add_Modefy = false;
            window_Voyage.mSCD_ID = mVesselSchedules.SCD_ID.ToString();
            window_Voyage.mUser_ID = userid;
            window_Voyage.mVoyages = theVoyage;
            window_Voyage.SCD_SLN_ID = int.Parse(theVoyage.VOY_SLN_ID.ToString());
            window_Voyage.Show();
        }
        //控制航次修改事件。
        private bool isSendEvent_Voyage = false;
        //航次新增，删除完成事件。
        void window_Voyage_OnAdd_ModefyEvent(object sender, MouseButtonEventArgs e)
        {
            if (mVesselSchedules != null)
            {
                clientService.GetVoyagesAsync(mVesselSchedules.SCD_ID);
                isSendEvent_Voyage = true;
            }
        }

        //点击维护航次箱量：
        private void btnVoyage_Amount_Container_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            if (btn != null)
            {
                ServiceReference_HB.UM_Voyages the_Voyage = dataGridVoyage.SelectedItem as ServiceReference_HB.UM_Voyages;
                if (the_Voyage == null)
                    return;

                ChildWindows.ChildWindow_VoyageAmount voyageAmount = new ChildWindows.ChildWindow_VoyageAmount(btn.Tag.ToString(), int.Parse(userid), mVesselSchedules.SCD_ID.ToString(), the_Voyage.VOY_IEFG);
                voyageAmount.OnAdd_ModifyEvent += new MouseButtonEventHandler(voyageAmount_OnAdd_ModifyEvent);
                voyageAmount.Show();
            }
        }
        //通知事件。
        void voyageAmount_OnAdd_ModifyEvent(object sender, MouseButtonEventArgs e)
        {
            clientService.GetVoyagesAsync(mVesselSchedules.SCD_ID);
        }
        #endregion
    }//end class
}
